var cc__decorate = __decorate;
var cc__awaiter = __awaiter;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2GameUser = require("GameUser");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2UIManager = require("UIManager");
var $2ccUtil = require("ccUtil");
var $2UIHelp = require("UIHelp");
var $2BaseUIPopup = require("BaseUIPopup");
var $2UIVMain = require("UIVMain");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_UICollect = /* */function (_h$default) {
  function _ctor() {
    var _this95;
    babel_classCallCheck(this, _ctor);
    _this95 = _callSuper(this, _ctor, arguments);
    _this95.closeBtn = null;
    _this95.enterBtn = null;
    _this95.receiveBtn = null;
    _this95.receivedLbl = null;
    return _this95;
  }
  babel_inherits(_ctor, _h$default);
  return babel_createClass(_ctor, [{
    key: "onClose",
    value: function onClose() {
      this.close();
    }
  }, {
    key: "onLoad",
    value: function onLoad() {
      var _this96 = this;
      var e = window.tt;
      e && e.onFavoriteStateChange && e.onFavoriteStateChange(function (e) {
        if (e) {
          $2GameUser.default.getInstance().setCollectedState(true);
          _this96.syncCollectionView();
          $2UIHelp.UIHelp.showTip("收藏成功");
        } else {
          console.log("收藏失败");
        }
      });
      this.syncCollectionView();
    }
  }, {
    key: "syncCollectionView",
    value: function syncCollectionView() {
      if ($2GameUser.default.getInstance().getCollectedState()) {
        this.enterBtn.active = false;
        if ($2GameUser.default.getInstance().getCollectionRewardClaimState()) {
          this.receiveBtn.active = false, this.receivedLbl.active = true;
        } else {
          this.receiveBtn.active = true, this.receivedLbl.active = false;
        }
      } else {
        this.enterBtn.active = true;
        this.receiveBtn.active = false;
        this.receivedLbl.active = false;
      }
    }
  }, {
    key: "onEnter",
    value: function onEnter() {
      var _this97 = this;
      var e = window.tt;
      e && e.showFavoriteGuide && e.showFavoriteGuide({
        type: "bar",
        content: "一键添加到我的小程序",
        position: "bottom",
        success(e) {
          if (e.isFavorited) {
            $2GameUser.default.getInstance().setCollectedState(true);
            _this97.syncCollectionView();
            $2UIHelp.UIHelp.showTip("收藏成功");
          }
        },
        fail(e) {
          console.log("引导组件展示失败", e);
          if ("showFavoriteGuide:fail Internal error: had added to favorites list" == e.errMsg) {
            console.log("已经收藏了");
            $2GameUser.default.getInstance().setCollectedState(true);
            _this97.syncCollectionView();
          }
        }
      });
    }
  }, {
    key: "onReceive",
    value: function onReceive() {
      return cc__awaiter(this, undefined, undefined, /* */babel_regeneratorRuntime().mark(function _callee5() {
        return babel_regeneratorRuntime().wrap(function _callee5$(_context6) {
          while (1) {
            switch (_context6.prev = _context6.next) {
              case 0:
                $2GameUser.default.getInstance().tili++;
                _context6.next = 3;
                return $2ccUtil.default.goldFlyEffect();
              case 3:
                $2EventCenter.default.postEvent($2EventDefine.default.GAME_TILI_INFO_UPDATE);
                $2UIHelp.UIHelp.showTip("领取1点体力");
                $2GameUser.default.getInstance().setCollectionRewardClaimState(true);
                this.syncCollectionView();
                $2UIManager.UIManager.getInstance().getUI($2UIVMain.default).syncCollectBtnState();
                this.close();
              case 9:
              case "end":
                return _context6.stop();
            }
          }
        }, _callee5, this);
      }));
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onEnable", this).call(this);
      this.closeBtn.on("click", this.onClose, this);
      this.enterBtn.on("click", this.onEnter, this);
      this.receiveBtn.on("click", this.onReceive, this);
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      babel_get(babel_getPrototypeOf(_ctor.prototype), "onDisable", this).call(this);
      this.closeBtn.off("click", this.onClose, this);
      this.enterBtn.off("click", this.onEnter, this);
      this.receiveBtn.off("click", this.onReceive, this);
    }
  }]);
}($2BaseUIPopup.default);
def_UICollect.className = "UICollect";
cc__decorate([ccp_property(cc.Node)], def_UICollect.prototype, "closeBtn", undefined);
cc__decorate([ccp_property(cc.Node)], def_UICollect.prototype, "enterBtn", undefined);
cc__decorate([ccp_property(cc.Node)], def_UICollect.prototype, "receiveBtn", undefined);
cc__decorate([ccp_property(cc.Node)], def_UICollect.prototype, "receivedLbl", undefined);
def_UICollect = cc__decorate([ccp_ccclass], def_UICollect);
exports.default = def_UICollect;